import { defineStore, storeToRefs } from 'pinia';
import {
  gethandlingPage,
  getBusinessDetail,
  getSpecialTreatmentInfo,
} from '/@/api/comprehensive/business';
import { messageFn } from '../../utils';
import { comprehensiveStore } from './home';
const comprehensive = comprehensiveStore();
const { ckeckList } = storeToRefs(comprehensive);
interface businessType {
  businessList: any[];
  total: 0;
  detailsList: {};
  businessDatails: [];
}

export const businessStore = defineStore('business_store', {
  state: (): businessType => {
    return {
      businessList: [],
      total: 0,
      detailsList: {},
      businessDatails: [],
    };
  },
  actions: {
    // 业务记录
    async getbusinessList(obj: object) {
      const params = {
        user_ids: ckeckList.value,
        ...obj,
      };
      const { code, data, msg } = await gethandlingPage(params);
      if (code === 0) {
        console.log(data, 'ddsfdsfdsfs');
        this.total = data.total;
        this.businessList = data.list;
        return true;
      } else {
        messageFn('error', msg);
      }
    },
    // 业务详情
    async getbusinessDetails(obj: object) {
      const { code, data, msg } = await getBusinessDetail(obj);
      if (code === 0) {
        this.businessDatails = data;
        return data;
      } else {
        messageFn('error', msg);
      }
    },
    // 账单详情
    async getSpaeciaInfo(obj: object) {
      const { code, data, msg } = await getSpecialTreatmentInfo(obj);
      if (code === 0) {
        this.detailsList = data;
        return data;
      } else {
        messageFn('error', msg);
      }
    },
  },
});
